<?php $javascript->link('jquery-1.3.2.min.js', false); ?>

<script type="text/javascript">
var num_teams = <?php echo count($registration['Team']); ?>;
var num_individuals = <?php echo count($registration['Individual']); ?>;
var num_quizmasters = <?php echo count($registration['Quizmaster']); ?>;
var num_housers = <?php echo count($registration['Housee']); ?>;
$(document).ready(function() {

    $("input").bind("keypress", function(e) {
        if (e.keyCode == 13) return false;
    });

    $("#add_team_button").click(function(){
        num_teams += 1;
        $('#teams tr:last').after(''+
           '<tr id="x_team'+num_teams+'">'+
           '    <td>Team</td>'+
           '    <td><input name="data[Team]['+num_teams+'][division]" type="radio" value="STVA" /></td>'+
           '    <td><input name="data[Team]['+num_teams+'][division]" type="radio" value="STVB" /></td>'+
           '    <td><input name="data[Team]['+num_teams+'][division]" type="radio" value="STR" /></td>'+
           '    <td><input name="data[Team]['+num_teams+'][division]" type="radio" value="YTVA" /></td>'+
           '    <td><input name="data[Team]['+num_teams+'][division]" type="radio" value="YTVB" /></td>'+
           '    <td><input name="data[Team]['+num_teams+'][division]" type="radio" value="YTRA" /></td>'+
           '    <td><input name="data[Team]['+num_teams+'][division]" type="radio" value="YTRB" /></td>'+
           '    <td><input name="data[Team]['+num_teams+'][division]" type="radio" value="RO" /></td>'+
           '    <td><input type="button" value="X" onclick="removeEntry(\'#x_team'+num_teams+'\'); return false;" /></td>'+
           '</tr>');
    });
    $("#add_individual_button").click(function(){
        num_individuals += 1;
        $('#individuals tr:last').after(''+
            '<tr id="x_individual'+num_individuals+'">'+
            '    <td><input name="data[Individual]['+num_individuals+'][name]" type="text" /></td>'+
            '    <td><input name="data[Individual]['+num_individuals+'][division]" type="radio" value="STVA" /></td>'+
            '    <td><input name="data[Individual]['+num_individuals+'][division]" type="radio" value="STVB" /></td>'+
            '    <td><input name="data[Individual]['+num_individuals+'][division]" type="radio" value="STR" /></td>'+
            '    <td><input name="data[Individual]['+num_individuals+'][division]" type="radio" value="YTVA" /></td>'+
            '    <td><input name="data[Individual]['+num_individuals+'][division]" type="radio" value="YTVB" /></td>'+
            '    <td><input name="data[Individual]['+num_individuals+'][division]" type="radio" value="YTR" /></td>'+
            '    <td><input type="button" value="X" onclick="removeEntry(\'#x_individual'+num_individuals+'\'); return false;" /></td>'+
            '</tr>');
    });
    $("#add_quizmaster_button").click(function(){
        num_quizmasters += 1;
        $('#quizmasters tr:last').after(''+
            '<tr id="x_quizmaster'+num_quizmasters+'">'+
            '    <td><input name="data[Quizmaster]['+num_quizmasters+'][name]" type="text" /></td>'+
            '    <td><input name="data[Quizmaster]['+num_quizmasters+'][can_do_STVA]" type="checkbox" /></td>'+
            '    <td><input name="data[Quizmaster]['+num_quizmasters+'][can_do_STVB]" type="checkbox" /></td>'+
            '    <td><input name="data[Quizmaster]['+num_quizmasters+'][can_do_STR]" type="checkbox" /></td>'+
            '    <td><input name="data[Quizmaster]['+num_quizmasters+'][can_do_YTVA]" type="checkbox" /></td>'+
            '    <td><input name="data[Quizmaster]['+num_quizmasters+'][can_do_YTVB]" type="checkbox" /></td>'+
            '    <td><input name="data[Quizmaster]['+num_quizmasters+'][can_do_YTRA]" type="checkbox" /></td>'+
            '    <td><input name="data[Quizmaster]['+num_quizmasters+'][can_do_YTRB]" type="checkbox" /></td>'+
            '    <td><input name="data[Quizmaster]['+num_quizmasters+'][can_do_RO]" type="checkbox" /></td>'+
            '    <td><input type="button" value="X" onclick="removeEntry(\'#x_quizmaster'+num_quizmasters+'\'); return false;" /></td>'+
            '</tr>');
    });
    $("#add_houser_button").click(function(){
        num_housers += 1;
        $('#housing tr:last').after(''+
            '<tr id="x_housee'+num_housers+'">'+
            '    <td><input name="data[Housee]['+num_housers+'][name]" type="text" /></td>'+
            '    <td><input name="data[Housee]['+num_housers+'][type]" type="radio" value="male-quizzer" /></td>'+
            '    <td><input name="data[Housee]['+num_housers+'][type]" type="radio" value="female-quizzer" /></td>'+
            '    <td><input name="data[Housee]['+num_housers+'][type]" type="radio" value="male-adult" /></td>'+
            '    <td><input name="data[Housee]['+num_housers+'][type]" type="radio" value="female-adult" /></td>'+
            '    <td><input name="data[Housee]['+num_housers+'][type]" type="radio" value="child" /></td>'+
            '    <td><input type="button" value="X" onclick="removeEntry(\'#x_housee'+num_housers+'\'); return false;" /></td>'+
            '</tr>');
    });
});

function removeEntry(id) {
    $(id).remove();
}

</script>

<?php echo $form->create('Registration'); ?>
    <!--<input type="hidden" name="data[Registration][id]" value="<?php echo $registration_id; ?>" />-->

    <h1>Bible Quizzing Tournament Registration</h1>

    <h2>1) Tournament Selection</h2>
        <select name="data[Registration][tournament_id]">
        <?php foreach($tournaments as $id=>$name): ?>
            <option value="<?php echo $id; ?>" <?php if ($registration['Registration']['tournament_id'] == $id) echo 'selected="selected"'; ?>><?php echo $name; ?></option> 
        <?php endforeach; ?>
        </select>

    <h2>2) Contact Information</h2> 
    <p> 
Enter information about your church and your quiz coach.  Please provide e-mail and phone number of the coach <u>who will be attending the tournament</u>, not the church's e-mail or phone.  We will use this information to contact you if the need arises.
    </p> 
    <table> 
        <tr> 
            <td>Church Name</td> 
            <td><input type="text" name="data[Registration][church_name]" value="<?php echo $registration['Registration']['church_name']; ?>" /></td> 
            <td>Conference</td> 
            <td><input type="text" name="data[Registration][conference]" value="<?php echo $registration['Registration']['conference']; ?>" /></td> 
        </tr> 
        <tr> 
            <td>Coach Name</td> 
            <td><input type="text" name="data[Registration][coach_name]" value="<?php echo $registration['Registration']['coach_name']; ?>" /></td> 
            <td>Email Address</td> 
            <td><input type="text" name="data[Registration][email]" value="<?php echo $registration['Registration']['email']; ?>" /></td> 
        </tr> 
        <tr> 
            <td>Daytime Phone</td> 
            <td><input type="text" name="data[Registration][daytime_phone]" value="<?php echo $registration['Registration']['daytime_phone']; ?>" /></td> 
            <td>Evening Phone</td> 
            <td><input type="text" name="data[Registration][evening_phone]" value="<?php echo $registration['Registration']['evening_phone']; ?>" /></td> 
        </tr> 
    </table> 
    <br /> 
    <table> 
        <tr> 
            <td>Number of people eating lunch</td> 
            <td><input type="text" name="data[Registration][number_for_lunch]" size="5" value="<?php echo $registration['Registration']['number_for_lunch']; ?>" /></td> 
        </tr> 
        <tr> 
            <td>Number of working quiz seats you are bringing</td> 
            <td><input type="text" name="data[Registration][number_of_seats]" size="5" value="<?php echo $registration['Registration']['number_of_seats']; ?>" /></td> 
        </tr> 
    </table> 
    <br /> 
    <h2>3) Team Setup</h2> 
    <p> 
        Enter the division of each team participating.
    </p> 
    <table id="teams"> 
        <tr> 
			<th></th> 
			<th>S<br />T<br />V<br />A</th> 
			<th>S<br />T<br />V<br />B</th> 
			<th><br />S<br />T<br />R</th> 
			<th>Y<br />T<br />V<br />A</th> 
			<th>Y<br />T<br />V<br />B</th> 
			<th>Y<br />T<br />R<br />A</th> 
			<th>Y<br />T<br />R<br />B</th> 
			<th><br /><br />R<br />O</th> 
            <th></th>
        </tr> 
        <?php $i=1; sort($registration['Team']); foreach($registration['Team'] as $team): ?>
        <tr id="x_team<?php echo $i; ?>"> 
            <td>Team</td> 
            <td><input name="data[Team][<?php echo $i; ?>][division]" type="radio" value="STVA" <?php if ($team['division'] == "STVA") echo 'checked="true"'; ?>/></td>
            <td><input name="data[Team][<?php echo $i; ?>][division]" type="radio" value="STVB" <?php if ($team['division'] == "STVB") echo 'checked="true"'; ?>/></td> 
            <td><input name="data[Team][<?php echo $i; ?>][division]" type="radio" value="STR"  <?php if ($team['division'] == "STR" ) echo 'checked="true"'; ?>/></td> 
            <td><input name="data[Team][<?php echo $i; ?>][division]" type="radio" value="YTVA" <?php if ($team['division'] == "YTVA") echo 'checked="true"'; ?>/></td> 
            <td><input name="data[Team][<?php echo $i; ?>][division]" type="radio" value="YTVB" <?php if ($team['division'] == "YTVB") echo 'checked="true"'; ?>/></td> 
            <td><input name="data[Team][<?php echo $i; ?>][division]" type="radio" value="YTRA" <?php if ($team['division'] == "YTRA") echo 'checked="true"'; ?>/></td> 
            <td><input name="data[Team][<?php echo $i; ?>][division]" type="radio" value="YTRB" <?php if ($team['division'] == "YTRB") echo 'checked="true"'; ?>/></td> 
            <td><input name="data[Team][<?php echo $i; ?>][division]" type="radio" value="RO"   <?php if ($team['division'] == "RO"  ) echo 'checked="true"'; ?>/></td> 
            <td><input type="button" value="X" onclick="removeEntry('#x_team<?php echo $i; ?>'); return false;" /></td>
            </tr> 
        <?php $i++; endforeach; ?>
    </table> 
    <input type="button" id="add_team_button" value="Add another team" /> 
    <br /> 
    <br /> 
    <h2>4) Individuals Setup</h2> 
    <p> 
        Enter the name and division of each quizzer participating in individual competition. 
    </p> 
    <table id="individuals"> 
        <tr> 
			<th>Name</th> 
			<th>S<br />T<br />V<br />A</th> 
			<th>S<br />T<br />V<br />B</th> 
			<th><br />S<br />T<br />R</th> 
			<th>Y<br />T<br />V<br />A</th> 
			<th>Y<br />T<br />V<br />B</th> 
			<th><br />Y<br />T<br />R</th> 
            <th></th>
        </tr> 
        <?php $i=1; sort($registration['Individual']); foreach($registration['Individual'] as $individual): ?>
        <!--<input type="hidden" name="data[Individual][id]" value="<?php echo $i; ?>" />-->
        <tr id="x_individual<?php echo $i; ?>"> 
        <td><input name="data[Individual][<?php echo $i; ?>][name]" type="text" value="<?php echo $individual['name']; ?>" /></td> 
<td><input name="data[Individual][<?php echo $i; ?>][division]" type="radio" value="STVA" <?php if ($individual['division'] == "STVA") echo 'checked="true"'; ?>/></td> 
<td><input name="data[Individual][<?php echo $i; ?>][division]" type="radio" value="STVB" <?php if ($individual['division'] == "STVB") echo 'checked="true"'; ?>/></td> 
<td><input name="data[Individual][<?php echo $i; ?>][division]" type="radio" value="STR"  <?php if ($individual['division'] == "STR" ) echo 'checked="true"'; ?>/></td> 
<td><input name="data[Individual][<?php echo $i; ?>][division]" type="radio" value="YTVA" <?php if ($individual['division'] == "YTVA") echo 'checked="true"'; ?>/></td> 
<td><input name="data[Individual][<?php echo $i; ?>][division]" type="radio" value="YTVB" <?php if ($individual['division'] == "YTVB") echo 'checked="true"'; ?>/></td> 
<td><input name="data[Individual][<?php echo $i; ?>][division]" type="radio" value="YTR"  <?php if ($individual['division'] == "YTR" ) echo 'checked="true"'; ?>/></td> 
            <td><input type="button" value="X" onclick="removeEntry('#x_individual<?php echo $i; ?>'); return false;" /></td>
        </tr> 
        <?php $i++; endforeach; ?>
    </table> 
    <input type="button" id="add_individual_button" value="Add another quizzer" /> 
    <br /> 
    <br /> 
    <h2>5) Quizmasters Setup</h2> 
    <p> 
        Enter the name of each quizmaster coming with your church, and check each of the divisions he or she is willing to quizmaster in.
    </p> 
    <table id="quizmasters"> 
        <tr> 
			<th>Name</th> 
			<th>S<br />T<br />V<br />A</th> 
			<th>S<br />T<br />V<br />B</th> 
			<th><br />S<br />T<br />R</th> 
			<th>Y<br />T<br />V<br />A</th> 
			<th>Y<br />T<br />V<br />B</th> 
			<th>Y<br />T<br />R<br />A</th> 
			<th>Y<br />T<br />R<br />B</th> 
			<th><br /><br />R<br />O</th> 
            <th></th>
        </tr> 
        <?php $i=1; sort($registration['Quizmaster']); foreach($registration['Quizmaster'] as $quizmaster): ?>
        <tr id="x_quizmaster<?php echo $i; ?>"> 
        <td><input name="data[Quizmaster][<?php echo $i; ?>][name]" type="text" value="<?php echo $quizmaster['name']; ?>" /></td> 
<td><input name="data[Quizmaster][<?php echo $i; ?>][can_do_STVA]" type="checkbox" <?php if ($quizmaster['can_do_STVA']) echo 'checked="true"'; ?>/></td> 
<td><input name="data[Quizmaster][<?php echo $i; ?>][can_do_STVB]" type="checkbox" <?php if ($quizmaster['can_do_STVB']) echo 'checked="true"'; ?>/></td> 
<td><input name="data[Quizmaster][<?php echo $i; ?>][can_do_STR]"  type="checkbox" <?php if ($quizmaster['can_do_STR'])  echo 'checked="true"'; ?>/></td> 
<td><input name="data[Quizmaster][<?php echo $i; ?>][can_do_YTVA]" type="checkbox" <?php if ($quizmaster['can_do_YTVA']) echo 'checked="true"'; ?>/></td> 
<td><input name="data[Quizmaster][<?php echo $i; ?>][can_do_YTVB]" type="checkbox" <?php if ($quizmaster['can_do_YTVB']) echo 'checked="true"'; ?>/></td> 
<td><input name="data[Quizmaster][<?php echo $i; ?>][can_do_YTRA]" type="checkbox" <?php if ($quizmaster['can_do_YTRA']) echo 'checked="true"'; ?>/></td> 
<td><input name="data[Quizmaster][<?php echo $i; ?>][can_do_YTRB]" type="checkbox" <?php if ($quizmaster['can_do_YTRB']) echo 'checked="true"'; ?>/></td> 
<td><input name="data[Quizmaster][<?php echo $i; ?>][can_do_RO]"   type="checkbox" <?php if ($quizmaster['can_do_RO'])  echo 'checked="true"'; ?>/></td> 
            <td><input type="button" value="X" onclick="removeEntry('#x_quizmaster<?php echo $i; ?>'); return false;" /></td>
        </tr> 
        <?php $i++; endforeach; ?>
    </table> 
    <input type="button" id="add_quizmaster_button" value="Add another quizmaster" /> 
    <br /> 
    <br /> 
    <h2>6) Housing Setup</h2> 
    <p> 
        Enter the name and type of each person who needs housing for your church.
    </p> 
    <table id="housing"> 
        <tr> 
			<th>Name</th> 
			<th>Male<br/>Quizzer</th> 
			<th>Female<br/>Quizzer</th> 
			<th>Male<br/>Adult</th> 
			<th>Female<br/>Adult</th> 
            <th><br/>Child</th>
            <th></th>
        </tr> 
        <?php $i=1; sort($registration['Housee']); foreach($registration['Housee'] as $housee): ?>
        <tr id="x_housee<?php echo $i; ?>"> 
        <td><input name="data[Housee][<?php echo $i; ?>][name]" type="text" value="<?php echo $housee['name']; ?>"/></td> 
            <td><input name="data[Housee][<?php echo $i; ?>][type]" type="radio" <?php if ($housee['type'] == 'male-quizzer') echo 'checked="true"'; ?> value="male-quizzer" /></td> 
            <td><input name="data[Housee][<?php echo $i; ?>][type]" type="radio" <?php if ($housee['type'] == 'female-quizzer') echo 'checked="true"'; ?> value="female-quizzer" /></td> 
            <td><input name="data[Housee][<?php echo $i; ?>][type]" type="radio" <?php if ($housee['type'] == 'male-adult') echo 'checked="true"'; ?> value="male-adult" /></td> 
            <td><input name="data[Housee][<?php echo $i; ?>][type]" type="radio" <?php if ($housee['type'] == 'female-adult') echo 'checked="true"'; ?> value="female-adult" /></td> 
            <td><input name="data[Housee][<?php echo $i; ?>][type]" type="radio" <?php if ($housee['type'] == 'child') echo 'checked="true"'; ?> value="child" /></td> 
            <td><input type="button" value="X" onclick="removeEntry('#x_housee<?php echo $i; ?>'); return false;" /></td>
        </tr> 
        <?php $i++; endforeach; ?>
    </table> 
    <input type="button" id="add_houser_button" value="Add another person" /> 
    <br />
    <br />
    <h2>7) Notes</h2>
    <p>
        Registration Notes (bringing broken seats, one adult not eating lunch, roommate preferences, etc.):
        <textarea name="data[Registration][notes]" cols="60" rows="6"><?php echo $registration['Registration']['notes']; ?></textarea>
    </p>
    
<?php echo $form->end('Update Registration'); ?>
